/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.agilelang.generate;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author RoderickNestor
 */
public class StringMacth {

    public static void main(String ar[]) {
        String[] list_params = {"name", "description", "category", ""};
        String[] list_m = {"SELECT fun($attr) FROM model", "INSERT INTO model(fun($attr)) values (fun( ? ))", "UPDATE model SET fun($attr = ? )", "db.users.insert({fun($attr: \"?\")} )"};

        Pattern MY_PATTERN = Pattern.compile("fun\\((.*?)\\)");
        for (String m_s : list_m) {
            Matcher m_select = MY_PATTERN.matcher(m_s);
            while (m_select.find()) {
                String s = m_select.group(1), aux = "";

                for (int p = 0; p < list_params.length - 1; p++) {
                    aux = aux + s.replace("$attr", list_params[p]) + ", ";
                    //System.err.println(" aux " + aux);
                }
                m_s = m_s.replace("fun(" + s + ")", aux.substring(0, aux.length() - 2));
                //System.err.println(s + " - " + m_s);

            }
            System.err.println(m_s);
        }

    }
}
